package com.itheima.controller;


import com.itheima.common.R;
import com.itheima.service.OssService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;


@RestController

@RequestMapping("/common")
public class CommonController {

    @Resource
    private OssService ossService;


    @PostMapping("/upload")
    public R<String> upload(@RequestParam MultipartFile file) {

        try {
            String s = ossService.uploadFileAvatar(file);
            if (s != null) {
                return R.success(s);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return R.error("上传失败");
    }

    @GetMapping("/download")
    public File download(String downloadFile) {

        return null;
    }

}
